//
//  HomeTableViewCell.m
//  mafengwo
//
//  Created by Mac on 16/3/10.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "HomeViewController.h"
#import "RaidersViewController.h"
#import "HotDestination.h"
#import "MonthModel.h"
#import "WebViewController.h"
#import "PAndHViewController.h"
@implementation HomeTableViewCell



- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];

    

    //头像logo
    _logo.layer.cornerRadius = (_logo.frame.size.width)/2;
    _logo.backgroundColor = [UIColor redColor];
    NSURL *url = [NSURL URLWithString:@"http://file31.mafengwo.net/M00/37/64/wKgBs1byEXiAJe7nAAChEGmqhkc60.jpeg"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    self.advertisementImageView.image = [UIImage imageWithData:data];


//    [self.btn setTitle:@"test" forState:UIControlStateNormal];
//    self.btn.backgroundColor = [UIColor blackColor];
//    [self.btn addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];



    //热门目的地
    //超值热卖button
    _sellingValue.layer.borderColor = [UIColor orangeColor].CGColor;
    _sellingValue.layer.borderWidth = 1;
    _sellingValue.layer.cornerRadius = 5;
    //collectionview
#pragma -mark这个地方不是应该用控制器设代理吗，响应者链
    [_hotCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"hot_cell"];
    _hotCollectionView.delegate = self;
    _hotCollectionView.dataSource = self;

    //查看更多button
    _seeMore.layer.borderColor = [UIColor orangeColor].CGColor;
    _seeMore.layer.borderWidth = 1;
    _seeMore.layer.cornerRadius = 5;
    _seeMore.clipsToBounds = YES;

    //目的地推荐单元格
    /*为什么这个地方我要这样粗暴的赋值呢，因为这几个月份块是固定的，只要获取当前系统的时间日期，知道月份，就能按顺序赋值了，超过12月的减掉12就回到了1月，这个地方的赋值的数据比较少就12个，等到数据量大的地方就能看到
     我做的数据解析类和数据model及赋值
     */

    [self loadMonthsData];

}

//单元格： 找攻略 订酒店 机+酒 当地游  ....
- (IBAction)searchRaidersAction:(id)sender {
    //要弹出的界面
    WebViewController *webVC = [[WebViewController alloc]init];
    NSURL *url = [NSURL URLWithString:@"https://m.mafengwo.cn/mdd/"];
    //界面属性赋值
    webVC.url =url;
    webVC.viewTitle = @"找攻略";
    [[self viewController] presentViewController:webVC animated:NO completion:nil];

}
//响应者链
- (UIViewController *)viewController {

    // 下一级响应者
    UIResponder *next = self.nextResponder;

    do {

        if ([next isKindOfClass:[UIViewController class]]) {

            return (UIViewController *)next;
        }

        next = next.nextResponder;

    } while (next != nil);

    return nil;

}
//机加酒
- (IBAction)planeAndHotelAction:(id)sender {
//    NSLog(@"点击了机加酒");
    PAndHViewController *pAndHVC = [[PAndHViewController alloc]init];
    pAndHVC.name = @"机➕酒";
    
    [[self viewController] presentViewController:pAndHVC animated:NO completion:nil];
}

-(void)loadMonthsData{

    //1.使用自己封装的数据解析类方法解析josn数据
    NSArray *rootDataArray = [DataParser jsonObjectFromFileName:@"destination_recommendation"];
    //创建一个数组（可变数组）用于存放每一个月份的model
    _dataList = [[NSMutableArray alloc]initWithCapacity:1];
    for (NSDictionary *dic in rootDataArray) {
        MonthModel *model = [[MonthModel alloc]initWithDic:dic];
        //将model存入到一个数组中,方便tableView一会使用
        [_dataList addObject:model];

    }
    NSDictionary *dic =@{@"months":_dataList};

    NSArray *arr = [dic objectForKey:@"months"];

    MonthModel *model1 = [arr objectAtIndex:0];
    MonthModel *model2 = [arr objectAtIndex:1];
    MonthModel *model3 = [arr objectAtIndex:2];
    MonthModel *model4 = [arr objectAtIndex:3];
    MonthModel *model5 = [arr objectAtIndex:4];
    MonthModel *model6 = [arr objectAtIndex:5];



//    @property(nonatomic,copy)NSString *month,*introduce,*image;

    _twoImg.image = [UIImage imageNamed:model2.image];
    _twoMonth.text = model2.month;
    _twoLabel.text = model2.introduce;

    _threeImg.image = [UIImage imageNamed:model3.image];
    _fourImg.image = [UIImage imageNamed:model4.image];
    _fiveImg.image = [UIImage imageNamed:model5.image];
    _sixImg.image = [UIImage imageNamed:model6.image];

    _threeMonth.text = model3.month;
    _fourMonth.text = model4.month;
    _fiveMonth.text = model5.month;
    _sixMonth.text = model6.month;

    _threeLabel.text = model3.introduce;
    _fourLabel.text = model4.introduce;
    _fiveLabel.text = model5.introduce;
    _sixLabel.text = model6.introduce;


}
//目的地推荐单元格的Button



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    

//self.nextResponder

}

- (IBAction)oneAction:(id)sender {
    NSLog(@"点击了1");
}

//collectionView的代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 6;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hot_cell" forIndexPath:indexPath];
    if (![cell.contentView viewWithTag:1001]) {
        HotDestination *hotDView = [[HotDestination alloc] initWithFrame:cell.contentView.bounds];
        hotDView.backgroundColor = [UIColor grayColor];
        hotDView.tag = 1001;
        [cell.contentView addSubview:hotDView];


    }

    //赋值部分
    HotDestination *hotDView = (HotDestination *)[cell.contentView viewWithTag:1001];
    hotDView.pujidao.text =[NSString stringWithFormat:@"普吉岛%ld号",indexPath.row];

//    [hotDView setImageVithURL:@"http://imgsrc.baidu.com/forum/pic/item/dbb44aed2e738bd4fb034eb5a18b87d6277ff910.jpg"];



    return cell;
}


- (IBAction)raidersAction:(id)sender {
//    NSLog(@"点击了订酒店");
    //要弹出的界面
    WebViewController *webVC = [[WebViewController alloc]init];
    NSURL *url = [NSURL URLWithString:@"https://m.mafengwo.cn/hotel/10444/?check_in_date=2016-05-29&check_out_date=2016-05-30&from="];
    //界面属性赋值
    webVC.url =url;
    webVC.viewTitle = @"订酒店";
    [[self viewController] presentViewController:webVC animated:NO completion:nil];}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//往期蜂首
- (IBAction)pastTopAction:(id)sender {

    
}


@end
